package cn.bytets.rpc.api.invoke;
import cn.bytets.rpc.api.message.*;
import cn.bytets.rpc.common.URL;

import java.util.concurrent.TimeUnit;

public  class AsyncToSyncInvoker<T> implements Invoker<T> {

    private Invoker<T> invoker;


    public AsyncToSyncInvoker(Invoker<T> invoker){
        this.invoker = invoker;
    }

    @Override
    public URL getUrl() {
        return invoker.getUrl();
    }

    /**
     * get service interface.
     *
     * @return service interface.
     */
    @Override
    public Class<T> getInterface() {
        return invoker.getInterface();
    }

    /**
     * invoke.
     *
     * @param invocation
     * @return result
     * @throws
     */
    @Override
    public Result invoke(Invocation invocation) {

        Result invoke = invoker.invoke(invocation);
        try{
            invoke.get(3,TimeUnit.SECONDS);
        } catch (Exception e){
            e.printStackTrace();
        }
        return invoke;
    }
}
